<?php 
## include required files
/*******************************/
require_once '../model/testimonials.php';
require_once '../model/users.php';
/*******************************/
## Create Objects
/*******************************/
$testimonialObj = new Model_Testimonials();
$userObj	=	new Model_Users();
/*******************************/
$users	=$userObj->getAllActiveUsers();
$smarty->assign('users',$users);

$testimonial_id = base64_decode($_GET['id']);

if(isset($_POST['edittestimonial_btn'])) {
	## apply PHP validation for required filed
	if(trim($_POST['testimonial_content']) != '') {
		$submenuArray = array();
		extract($_POST);	
		$testimonialArray['user'] 		= return_post_value($user);//$_SESSION["admin_firstname"].' '.$_SESSION["admin_lastname"];	
		$testimonialArray['testimonial_content']        = strip_tags(return_post_value($testimonial_content));
		$testimonialObj->editTestimonialById($testimonialArray,$testimonial_id);
		$_SESSION['msg'] = "<div class='success_msg'><span>Testimonials edited successfully</span></div>";
		header('location:'.SITE_URL.'/admin/home.php?q=testimonials&page='.$_POST['page']);
		exit;
	} else {// php validation else
		$_SESSION['msg'] = '<div class="error_msg"><span>Please enter testimonial content</span></div>';
	}
	// main if closed
}

if($_GET['id']!=''&& $_GET['action']=='edit') {
	
	$testimonialArray = $testimonialObj->getTestimonialDetailsById($testimonial_id);
	$smarty->assign('testimonialArray', $testimonialArray);
}

## Assign success or error msg to smarty variable and unset session variable
if(trim($_SESSION['msg']) != '') {
	$smarty->assign('msg', $_SESSION['msg']);
	unset($_SESSION['msg']);
}

## Set active class variable for left menu
$smarty->assign('activeclass', 'testimonials');
$smarty->assign('mainmenu', '2');
## Unset all the objects created which are on this page
unset($testimonialObj);

$smarty->display(TEMPLATEDIR_ADMIN. 'testimonials/edittestimonial.tpl');
unset($smarty);
?>